package com.runchamp;

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.internal.app.WindowDecorActionBar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;

import com.runchamp.util.DistanceCircleView;

/* A list of races the user participated in */
public class RaceHistoryInfoActivity extends ActionBarActivity {
    public de.hdodenhof.circleimageview.CircleImageView circle;
    TextView distanceTextView;
    TextView RaceDateTextView;
    TextView ActualTimeTextView;
    TextView ActualDistanceTextView;
    TextView gradeTextView;
    TextView isFinishedTextView;
    TextView positionTextView;
    private Bundle raceHistoryBundle;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_race_history_info);
        raceHistoryBundle = this.getIntent().getExtras();

        //connect to xml
        distanceTextView = (TextView) findViewById(R.id.text_distance);
        RaceDateTextView = (TextView) findViewById(R.id.text_race_date);
        ActualTimeTextView = (TextView) findViewById(R.id.text_actual_run_time);
        gradeTextView = (TextView) findViewById(R.id.text_grade);
        ActualDistanceTextView = (TextView) findViewById(R.id.text_actual_distance);
        isFinishedTextView = (TextView) findViewById(R.id.text_is_finished);
        positionTextView = (TextView) findViewById(R.id.text_position);

        //set text and view
        distanceTextView.setText(raceHistoryBundle.getString("Distance"));
        circle = (de.hdodenhof.circleimageview.CircleImageView) findViewById(R.id.row_circle);
        DistanceCircleView.setCircle(raceHistoryBundle.getString("Distance"), circle, distanceTextView, (TextView) findViewById(R.id.text_km));
        RaceDateTextView.setText(raceHistoryBundle.getString("RaceDate"));
        ActualTimeTextView.setText(raceHistoryBundle.getString("ActualTime"));
        gradeTextView.setText(raceHistoryBundle.getString("Grade"));
        ActualDistanceTextView.setText(raceHistoryBundle.getString("ActualDistance") + " km");
        isFinishedTextView.setText(raceHistoryBundle.getString("isFinished"));
        positionTextView.setText(raceHistoryBundle.getString("position"));

        //action bar
        android.support.v7.app.ActionBar actionBar = getSupportActionBar();
        WindowDecorActionBar bar = (WindowDecorActionBar) actionBar;
        bar.setDisplayHomeAsUpEnabled(true);
        bar.setHomeButtonEnabled(true);
        actionBar.setHomeButtonEnabled(true);
        actionBar.setDisplayHomeAsUpEnabled(true);

        actionBar.show();
        bar.show();
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_race_history_info, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        switch (id) {
            case R.id.action_settings:
                return true;
            case 16908332:
                finish();
                //this.overridePendingTransition(R.anim.nothing, R.anim.slide_out_right);
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }
}
